#ifndef _BCS_MANAGER_H_
#define _BCS_MANAGER_H_

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "urlcode.h"
#include "base64.h"
#include "hmac_sha1.h"
#include <string>
#include "curl/curl.h"
#include <vector>
#include <deque>

typedef size_t (*List_CallBack)(void *ptr, size_t size, size_t nmemb, void *stream);

struct BCSFileInfo
{
	std::string filename;
	std::string objName;
};

class BCSDelegate
{
public:
	virtual void willDownloadFile(const char* filename) = 0;
	virtual void willUploadFile(const char* filename) = 0;

	virtual void didDownloadFile(const char* filename) = 0;
	virtual void didUploadFile(const char* filename) = 0;
};

class BCSManager
{
protected:
	BCSManager():m_strFlag("MBO"), m_pDelegate(0){};

public:
	~BCSManager(){};

	static BCSManager* sharedBCSManager();

	std::string calcUrl(const char* filename, const char* objName, const char* op);
	void uploadFile(const char* filename, const char* objName);
	void downloadFile(const char* filename, const char* objName);

	void setAccessKey(const char* accessKey);
	void setSecretKey(const char* secretKey);
	void setBucket(const char* bucket);

	void setDelegate(BCSDelegate* pDelegage);

	int getDownloadCount() { return m_downloadQue.size(); }
	int getUploadCount() { return m_uploadQue.size(); }

	bool readDatabase(const char* sql, List_CallBack fun, void* pOutData);
	bool writeDatabase(const  char* sql, const char* condition=NULL);

	void tick(float dt);
private:
	std::string m_strAccessKey;
	std::string m_strSecretKey;
	std::string m_strBucket;
	std::string m_strFlag;


	std::deque<BCSFileInfo>		m_downloadQue;
	std::deque<BCSFileInfo>		m_uploadQue;

	BCSDelegate* m_pDelegate;
};
#endif